
package com.showcai.controller.systemSet;

import com.showcai.controller.base.WeChatBaseController;
import com.showcai.module.ApplyMaintain;
import com.showcai.result.ResultObj;
import com.showcai.result.ReturnCode;
import com.showcai.service.ApplyMaintainService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by lutao on 2017/7/14.
 */
@RequestMapping("/systemSet")
@Controller
public class SystemSetController extends WeChatBaseController {

    @Autowired
    ApplyMaintainService applyMaintainService;
    /**
     * 常见问题
     * @return
     */
    @RequestMapping(value = "/question")
    public ModelAndView question() {
        logger.info("question==================================>>>>>>");
        ModelAndView mov = new ModelAndView();
        String views = "systemSet/web/question";
        if (getIsMobile()) {
         //   super.oauth2();
            views = "systemSet/wap/question";
        }
        mov.setViewName(views);
        return mov;
    }

    /**
     * 申请维修
     * @return
     */
    @RequestMapping(value = "/maintenance")
    public ModelAndView maintenance(ApplyMaintain applyMaintain) {
        logger.info("maintenance==================================>>>>>>");
       // applyMaintainService.insertApplyMaintain(applyMaintain);
        ModelAndView mov = new ModelAndView();
        String views = "systemSet/web/maintenance";
        if (getIsMobile()) {
         //   super.oauth2();
            views = "systemSet/wap/maintenance";
        }
        mov.setViewName(views);
        return mov;
    }
    /**
     * 添加申请维修
     * @return
     */
    @RequestMapping(value = "/applyMaintain")
    @ResponseBody
    public String applyMaintain(@RequestParam("photo") MultipartFile[] photo, ApplyMaintain applyMaintain) {

        ResultObj resultObj = new ResultObj();
        try {

            logger.info("photo====count============>>>"+photo.length);

            String filePath = "showcai/applyMaintain/";
            String photos="";
            for (int i=0;i<photo.length;i++){
                if(i>0){
                    photos+=",";
                }
                photos += super.upLoadFile(photo[i].getInputStream(), filePath);
            }
            logger.info(applyMaintain.getBreakdownReason());
            logger.info("获取的图片路径——————"+photos);
            if (StringUtils.isNotBlank(photos)) {
                applyMaintain.setPicPath(photos);
            }
            applyMaintainService.insertApplyMaintain(applyMaintain);
        }
        catch (Exception e) {
            resultObj.setCode(ReturnCode.FAIL.getCode());
            resultObj.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return resultObj.toJson();
    }
    /**
     * 软件使用许可协议
     * @return
     */
  @RequestMapping(value = "/license")
    public ModelAndView license() {
        logger.info("license==================================>>>>>>");
        ModelAndView mov = new ModelAndView();
        String views = "systemSet/web/license";
        if (getIsMobile()) {
         //   super.oauth2();
            views = "systemSet/wap/license";
        }
        mov.setViewName(views);
        return mov;
    }

    /**
     * 用户服务条款
     * @return
     */
  @RequestMapping(value = "/customerService")
    public ModelAndView customerService() {
        ModelAndView mov = new ModelAndView();
        String views = "systemSet/web/customerService";
        if (getIsMobile()) {
         //   super.oauth2();
            views = "systemSet/wap/customerService";
        }
        mov.setViewName(views);
        return mov;
    }



}
